====================================
International exchange rates continue to (negatively) impact our bottom line.
We want to reflect the upds and downs of rate movements (a.k.a. currency appreciation and depreciation) to better understand exchange rate volitility.
exrates.csv, provided by our business partnersif and else statements to define a new column direction and house this new information in a data frameImporting & examining our data
head() shows our first few entriestail() shows our last few entriesstr() shows the structure of the datasummary() shows a crisp, clean summary of descriptive statslibrary(zoo)
library(xts)
library(ggplot2)
exrates <- na.omit(read.csv("data/exrates.csv", header = TRUE))
# head(exrates)
plot(head(exrates))
plot(tail(exrates))
plot(head(exrates), tail(exrates))
# tail(exrates)
# print('======= STRUCTURE =======')
# str(exrates)
# print('======= SUMMARY =======')
# summary(exrates)
Constructing a new data frame with additional calculations to help better address our business question
size column by taking the absolute value of what we created in (1) above because size is an indicator of volititydirection column by using ifelse statements to determine the “direction” of the market– a. Split into date and rates – b. Make an xts object with row and names equal to the dates 5. Creating our new data frame 6. Viewing our data frame using ggplot2 and plotly
exrates.r <- diff(log(as.matrix(exrates[, -1]))) * 100
# head(exrates.r)
# tail(exrates.r)
# str(exrates.r)
size <- na.omit(abs(exrates.r))
# head(size)
direction <- ifelse(exrates.r > 0, 1, ifelse(exrates.r < 0, -1, 0))
dates <- as.Date(exrates$DATE[-1], "%m/%d/%Y")
values <- cbind(exrates.r, size, direction)
exrates.df <- data.frame(dates = dates, returns = exrates.r, size = size, direction = direction)
exrates.xts <- na.omit(as.xts(values, dates))
exrates.zr <- na.omit(as.zooreg(exrates.xts))
library(ggplot2)
library(plotly)
title.chg <- "Exchange Rate Percent Changes"
p1 <- autoplot.zoo(exrates.xts[,1:4]) + ggtitle(title.chg) + ylim(-5, 5)
p2 <- autoplot.zoo(exrates.xts[,5:8]) + ggtitle(title.chg) + ylim(-5, 5)
ggplotly(p1)
acf(coredata(exrates.xts[ , 1:4]))
acf(coredata(exrates.xts[ , 5:8]))
pacf(coredata(exrates.xts[ , 1:4]))
pacf(coredata(exrates.xts[ , 5:8]))
data_moments <- function(data){
library(moments)
library(matrixStats)
mean.r <- colMeans(data)
median.r <- colMedians(data)
sd.r <- colSds(data)
IQR.r <- colIQRs(data)
skewness.r <- skewness(data)
kurtosis.r <- kurtosis(data)
result <- data.frame(mean = mean.r, median = median.r, std_dev = sd.r, IQR = IQR.r, skewness = skewness.r, kurtosis = kurtosis.r)
return(result)
}
answer <- data_moments(exrates.xts[,5:8])
answer <- round(answer, 4)
knitr::kable(answer)
| mean | median | std_dev | IQR | skewness | kurtosis | |
|---|---|---|---|---|---|---|
| USD.EUR | 0.7185 | 0.5895 | 0.5499 | 0.7506 | 1.3773 | 6.3808 |
| USD.GBP | 0.6884 | 0.5601 | 0.6565 | 0.6588 | 4.0555 | 34.3779 |
| USD.CNY | 0.1700 | 0.1118 | 0.2233 | 0.1536 | 4.9157 | 41.4959 |
| USD.JPY | 0.8310 | 0.6358 | 0.7371 | 0.8352 | 1.6373 | 6.3185 |
FIN.